package rs.etf.es.algorithm.states;

import java.io.Serializable;
import java.util.ArrayList;

import rs.etf.es.algorithm.Algorithm;
import rs.etf.es.algorithm.AlgorithmState;
import rs.etf.es.algorithm.Constants;
import rs.etf.es.algorithm.JTextAreaLogger;
import rs.etf.es.algorithm.Node;
import rs.etf.es.algorithm.NodeAddressBook;

public class SetDefaultLambdaValuesState implements AlgorithmState, Serializable {

    private Algorithm algorithm;

    @Override
    public void performAction() {
	ArrayList<Node> nodes = NodeAddressBook.instance().getAllNodes();

	for (Node i : nodes) {
	    for (String value : i.getValues()) {
		i.getLambdaValues().put(value, Constants.DEFAULT_LAMBDA_VALUE);
		JTextAreaLogger.instance().log("Setting \u03BB lambda value for " + value + " in variable " + i + " to 1");
		// AlgorithmBlocker.instance().stopHere();
	    }
	}

	SetDefaultLambdaMessagesState newState = new SetDefaultLambdaMessagesState();
	newState.setAlgorithm(algorithm);
	algorithm.pushAlgorithmState(newState);
    }

    @Override
    public void setAlgorithm(Algorithm algorithmClass) {
	algorithm = algorithmClass;
    }

    public SetDefaultLambdaValuesState clone() {
	SetDefaultLambdaValuesState newState = new SetDefaultLambdaValuesState();
	newState.setAlgorithm(algorithm);
	return newState;
    }

    @Override
    public void refreshNodes() {

    }

}
